load("@fbcode_macros//build_defs:native_rules.bzl", "buck_filegroup")
load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary")
load("@fbcode_macros//build_defs/lib:rust_oss.bzl", "rust_oss")
load(
    "//eden/mononoke/tests/integration/facebook:fb_manifest_deps.bzl",
    "dott_test",
)

oncall("scm_server_treehugger")

buck_filegroup(
    name = "test_fixtures",
    srcs = [
        "commitsync/all.json",
        "commitsync/all_with_flipped_config.json",
        "commitsync/current.json",
        "commitsync/current.toml",
        "commitsync/flipped_config.json",
        "commitsync/flipped_config.toml",
        "cross_repo/library-git-submodules-config-setup.sh",
        "cross_repo/library-git-submodules-helpers.sh",
        "cross_repo/library-git-submodules-repos-setup.sh",
        "dbrtest_runner.py",
        "fixtures/repo_with_newline_author_commit.tar.xz",
        "gitexport_library.sh",
        "library.sh",
        "library-commit.sh",
        "library-git-lfs.sh",
        "library-push-redirector.sh",
        "library-snapshot.sh",
        "raw_text.txt",
    ],
)

dott_test(
    name = "library-unit-tests",
    dott_files = glob(["test-library-*.t"]),
    deps = [
        "//eden/mononoke/tools/admin:admin",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)

python_binary(
    name = "integration_runner_real",
    srcs = ["integration_runner_real.py"],
    main_function = "eden.mononoke.tests.integration.integration_runner_real.run",
    deps = [
        "fbsource//third-party/pypi/click:click",
        "//eden/mononoke/tests/integration/facebook:lib_buck",
        "//libfb/py:log",
    ] if rust_oss.is_oss_build() else [
        "fbsource//third-party/pypi/click:click",
        "//eden/mononoke/tests/integration/facebook:lib_buck",
        "//eden/mononoke/tests/integration/facebook:lib_runner",
        "//libfb/py:log",
    ],
)

python_binary(
    name = "get_free_socket",
    srcs = ["get_free_socket.py"],
    main_module = "eden.mononoke.tests.integration.get_free_socket",
)

python_binary(
    name = "urlencode",
    srcs = ["urlencode.py"],
    main_module = "eden.mononoke.tests.integration.urlencode",
)

dott_test(
    name = "aliasverify",
    dott_files = ["test-alias-verify.t"],
    deps = [
        "//eden/mononoke:aliasverify",
        "//eden/mononoke:mononoke",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)

dott_test(
    name = "benchmark-filestore",
    dott_files = ["test-benchmark-filestore.t"],
    deps = [
        "//eden/mononoke/benchmarks/filestore:benchmark_filestore",
    ],
)

dott_test(
    name = "blobstore-healer",
    dott_files = ["test-blobstore-healer.t"],
    deps = [
        "//eden/mononoke:blobimport",
        "//eden/mononoke:blobstore_healer",
    ],
)

dott_test(
    name = "blobstore-healer-mysql",
    dott_files = ["test-blobstore-healer.t"],
    use_mysql = True,
    deps = [
        "//eden/mononoke:blobimport",
        "//eden/mononoke:blobstore_healer",
    ],
)

dott_test(
    name = "bonsai-verify",
    dott_files = ["test-bonsai-verify.t"],
    deps = [
        "//eden/mononoke:bonsai_verify",
        "//eden/mononoke/tools/admin:admin",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)

dott_test(
    name = "check-git-wc",
    dott_files = ["test-check-git-wc.t"],
    deps = [
        "//eden/mononoke:check_git_wc",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)

dott_test(
    name = "filenodes",
    dott_files = glob([
        "test-filenodes*.t",
    ]),
    deps = [
        "//eden/mononoke:mononoke",
        "//eden/mononoke/tools/admin:admin",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)

dott_test(
    name = "lfs",
    # These tests have been vetted to run well without network access. Please investigate any failure thoroughly before disabling.
    disable_all_network_access_target = True,
    dott_files =
        [
            "test-push-protocol-lfs.t",
        ] + glob(
            [
                "test-infinitepush-*lfs.t",
                "test-lfs*.t",
                "test-remotefilelog-lfs*.t",
            ],
            exclude = ["test-lfs-server*.t"],
        ),
    deps = [
        "//eden/mononoke:blobimport",
        "//eden/mononoke:mononoke",
        "//eden/mononoke/lfs_server:lfs_server",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)

dott_test(
    name = "microwave",
    dott_files =
        [
            "test-cache-warmup-microwave.t",
        ],
    deps = [
        "//eden/mononoke:mononoke",
        "//eden/mononoke/microwave:builder",
        "//eden/mononoke/tools/admin:admin",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)

dott_test(
    name = "packer",
    dott_files = ["test-packer.t"],
    deps = [
        "//eden/mononoke:blobimport",
        "//eden/mononoke:packer",
    ],
)

dott_test(
    name = "redaction",
    dott_files = glob(["test-redaction*.t"]),
    deps = [
        "//eden/mononoke:blobimport",
        "//eden/mononoke:mononoke",
        "//eden/mononoke/tools/admin:admin",
    ],
)

dott_test(
    name = "restore-keys",
    dott_files = glob(["test-restore-keys*.t"]),
    deps = [
        "//eden/mononoke:blobimport",
        "//eden/mononoke/tools/admin:admin",
        "//eden/mononoke/walker:walker",
    ],
)

dott_test(
    name = "testtool",
    dott_files = glob([
        "test-testtool-*.t",
    ]),
    deps = [
        "//eden/mononoke/tools/admin:admin",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)

dott_test(
    name = "streaming-clone",
    dott_files = glob(["test-streaming-clone*.t"]),
    deps = [
        "//eden/mononoke:mononoke",
        "//eden/mononoke/streaming_clone:new_streaming_clone",
        "//eden/mononoke/tools/testtool:testtool",
    ],
)
